﻿using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace MediaBrowser.Entities
{
    /// <summary>
    /// Classe Métier Média
    /// </summary>
    public class Media : BaseItem, ICloneable, IDataErrorInfo
    {
        private String urlImage;
        public String UrlImage
        {
            get
            {
                return urlImage;
            }
            set
            {
                urlImage = value;
                OnPropertyChanged("UrlImage");
            }
        }

        private String urlContent;
        public String UrlContent
        {
            get
            {
                return urlContent;
            }
            set
            {
                urlContent = value;
                OnPropertyChanged("UrlContent");
            }
        }
        public Category Category { get; set; }

        public List<MediaItem> MediaItems { get; set; }

        public Media(int id, String name, DateTime dateCreation, String description, Category category,
                     String urlImage, String urlContent)
            : base(id, name, dateCreation, description)
        {
            this.Category = category;
            this.UrlImage = urlImage;
            this.UrlContent = urlContent;
            MediaItems = new List<MediaItem>();
        }

        #region ICloneable Membres

        public object Clone()
        {
            Category c = Category == null ? null : (Category)Category.Clone();
            return new Media(Id, Name, DateCreation, Description, c, UrlImage, UrlContent);
        }

        #endregion

        #region IDataErrorInfo Membres

        public string Error
        {
            get { throw new NotImplementedException(); }
        }

        public string this[string columnName]
        {
            get
            {
                string result = null;

                if (columnName == "Name")
                {
                    if (String.IsNullOrEmpty(Name))
                        result = "Le Nom est un champ obligatoire";
                }
                else if (columnName == "Description")
                {
                    if (String.IsNullOrEmpty(Description))
                        result = "La Description est un champ obligatoire";
                }
                else if (columnName == "UrlImage")
                {
                    if (String.IsNullOrEmpty(UrlImage))
                        result = "L'affiche est obligatoire";
                }

                return result;
            }

        }

        #endregion
    }
}
